package com.arithmeticEveryDay.__1_enumeration;

import java.math.BigInteger;

/*

输入一个正整数n，按从小到大的顺序输出所有行如abcde / fghij = n的表达式，
其中a~j恰好对应0~9的一个排列，2 <= n <= 79

输入：
62

输出：
79546 / 01283 = 62
94736 / 01528 = 62

方法一：
从123456789枚举到9876543210(这里还忘了判断是否是0~9的排列了)
分母mom = 9876543210 % 100000 = 43210
分子son = (9876543210 - 43210) / 100000 = 98765
数据量太大，几乎无法运行

方法二：
123456789 % 10 = 9
12345678 % 10 = 8

 */

import java.util.Scanner;

public class __3_Division {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        {
            /*
            // 方法一
            Scanner scan = new Scanner(System.in);
            int n = scan.nextInt();
            BigInteger bigN = BigInteger.valueOf(n);
            BigInteger max = new BigInteger("9876543210");
            BigInteger i = BigInteger.valueOf(123456789);
            BigInteger ONE = BigInteger.valueOf(1);
            BigInteger TenHundred = BigInteger.valueOf(100000);
            while (i.compareTo(max) <= 0) {
                BigInteger mom = i.remainder(TenHundred);
                BigInteger son = i.subtract(mom).divide(TenHundred);
                if (mom.divide(son).compareTo(bigN) == 0) {
                    System.out.println(son + " / " + mom + " = " + bigN);
                }
                i = i.add(ONE);
            }
            */
        }
        {
            // 方法二
            Scanner scan = new Scanner(System.in);
            int n = scan.nextInt();
            for (int mom = 1234; mom <= 98765; mom++) {
                int son = mom * n;
                if (son < 100000) {
                    if (judge(son, mom)) {
                        System.out.print(son + " / ");
                        if(mom < 10000) {
                            System.out.print("0");
                        }
                        System.out.println(mom + " = " + n);
                    }
                }
            }
        }
    }

    private static boolean judge(int son, int mom) {
        // TODO Auto-generated method stub
        
        int[] arr = new int[10];
        for (int i = 0; i < 5; i++) {
            arr[i] = mom % 10;
            mom /= 10;
        }
        for (int i = 5; i < 10; i++) {
            arr[i] = son % 10;
            son /= 10;
        }
        for (int i = 0; i < 9; i++) {
            for (int j = i + 1; j < 10; j++) {
                if (arr[i] == arr[j]) {
                    return false;
                }
            }
        }
        return true;
    }

}
